function [user_pairs, user_positions] = NOMA()
 clear all;
 close all;
 clc;
%% 参数设置

N = 50;                   % 实NOMA用户对总数
% 生成真实用户的位置
ground_area = 1000;       % 1000 x 1000的区域
user_positions = zeros(2*N, 3);
for i = 1:2*N
    user_positions(i, :) = [ground_area*rand(), ground_area*rand(), 0];
end
%% 用户配对，形成NOMA用户对
% 将用户两两配对
user_pairs = zeros(N, 2);
remaining_users = 1:2*N; % 所有用户的索引
for i = 1:N
    if isempty(remaining_users)
        break; % 如果没有剩余用户，退出循环
    end
    
    % 选择第一个剩余用户作为参考用户
    user1_idx = remaining_users(1);
    user1_pos = user_positions(user1_idx, 1:2);
    
    % 计算所有其他剩余用户到该用户的距离
    distances = zeros(length(remaining_users)-1, 1);
    for j = 2:length(remaining_users)
        user2_idx = remaining_users(j);
        user2_pos = user_positions(user2_idx, 1:2);
        distances(j-1) = norm(user1_pos - user2_pos);
    end
    
    % 找到距离最近的用户
    [~, min_idx] = min(distances);
    user2_idx = remaining_users(min_idx+1); % +1是因为distances从remaining_users的第2个开始
    
    % 记录配对结果
    user_pairs(i, 1) = user1_idx;
    user_pairs(i, 2) = user2_idx;
    
    % 从剩余用户列表中移除这两个用户
    remaining_users = setdiff(remaining_users, [user1_idx, user2_idx]);
end


end
